package com.drawingtimer.admin.utils.sign;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public class ErpSign {

	public static String getSha256(String[] input) {

		Arrays.sort(input);

		// SHA1加密的话改成MessageDigest.getInstance("SHA-1");

		MessageDigest sha256 = null;
		try {
			sha256 = MessageDigest.getInstance("SHA-256");
			for (String str : input) {

				sha256.update(str.getBytes("UTF-8"));

			}
		}
		catch (NoSuchAlgorithmException e) {
			throw new RuntimeException(e);
		}
		catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}

		byte[] hashBytes = sha256.digest();

		StringBuilder hashString = new StringBuilder();

		for (byte b : hashBytes) {

			String hex = Integer.toHexString(0xff & b);

			if (hex.length() == 1) {

				hashString.append('0');

			}

			hashString.append(hex);

		}

		return hashString.toString();

	}

}
